#include <bits/stdc++.h>
using namespace std;

const int N = 2e5+5;
int n, a[N], c[N], co[N], ans;

void dfs(int u) {
    if (u > n) {
        int res = 0;
        for (int i = 1; i <= n; ++i) res += c[i];
        ans = max(res, ans);
        return;
    }
    co[u] = 0;
    for (int i = u-1; i; --i) {
        if (co[i] == 0) {
            c[u] = (a[u] == a[i] ? a[u] : 0);
            break;
        }
    }
    dfs(u+1);
    co[u] = 1;
    for (int i = u-1; i; --i) {
        if (co[i] == 1) {
            c[u] = (a[u] == a[i] ? a[u] : 0);
            break;
        }
    }
    dfs(u+1);
    return;
}

void solve() {
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    ans = 0;
    c[1] = 0;
    dfs(1);
    cout << ans << "\n";
    return;
}

signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    int T;
    cin >> T;
    while (T--) solve();
    return 0;
}